<?php
#
# author: Phil Spagnolo
# (c)2010 South Hill Calvary Chapel
#
include_once("./root.inc.php");
include("${root}/mysql/database_info.php");
include("${root}/common.php");
include("${root}/mysql/common.php");
connect_select_test("servants");
function ministry_info($title, $link_names, $links, $schedule) 
{
	$a = count($link_names);
	$b = count($links);
	if ($a != $b) {
		die ("Error:  The link_names and links array must be the same length.");
		return;
	}

	printf("<h4>\n");
	printf("\t%s\n",$title);
	printf("</h4>\n");
	printf("<div class='paragraph'>\n");
	printf("\t<ul>\n");
	if ($schedule) {
		$schedules = explode(",", $schedule);
		for ($s=0;$s<count($schedules);$s++){
			$title = explode(":", $schedules[$s])[0];
			$link = explode(":", $schedules[$s])[1];
			printf("\t\t<li>\n");
			printf("\t\t%s:  \n", $title);
			find_schedules($link);
			printf("\t\t</li>\n");
		}
	}
	for ($i=0; $i < $b; $i++) {
		printf("\t\t<li>\n");
		printf("<a href='%s' target='_blank'>%s</a>\n", 
		     $links[$i], $link_names[$i]);
		printf("\t\t</li>\n");
	}
	printf("\t\t</ul>\n");
	printf("</div>\n");

}
function printBlock($name)
{
	$blockResult = mysql_query("SELECT * FROM `servants` WHERE `name`='$name'");
	while ($info = mysql_fetch_array($blockResult)) {
		printf("<div class='paragraph'>%s</div>\n", $info['description']);
		$link_names = explode("\n", $info['titles']);
		$links = explode("\n", $info['links']);
		if ($link_names[0] != null){
			ministry_info($name, $link_names, $links, $info['DBTag']); 
		} else {
			ministry_info($name, null, null, $info['DBTag']);
		}
	}
}
$title = "SHCC Ministers";
$meta_key='setup, tear down, serve, facility, chairs, ushers, tithes';
$meta_desc="Ministry resources for the crew at South Hill Calvary Chapel.";
print_html_head($title ,$meta_key,$meta_desc);
print_java_head(NULL);
begin_body();
page_title($title);
$greeting = mysql_fetch_array(mysql_query("SELECT * FROM `servants` WHERE `name`='Greeting'"));
printf("<div class='paragraph'>%s</div>\n", $greeting['description']);
$pageContentResult = mysql_query("SELECT * FROM `servants` WHERE `name`!='Greeting' ORDER BY `name` ASC");
while ($pageContent = mysql_fetch_array($pageContentResult)){
	printBlock($pageContent['name']);
}
end_page_title(); 
end_body();
?>